/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package org.apt.matrimony.methods;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.util.Calendar;
import java.util.Date;
import org.apt.matrimony.db.MyConnection;
import org.apt.matrimony.utils.Tools;

/**
 *
 * @author yoko
 */
public class Inserts {
  public static boolean sendRequest(String fromUser,String text,int toUser){
       Connection cnn=null;
        PreparedStatement stm=null;
        int fromUserId=-1;
     try {
         fromUserId=selects.getAccountIdByAccountName(fromUser);
         Calendar cal=Calendar.getInstance();
         Date time=cal.getTime();
         String sTime=Tools.convertTime2String(time);
         String sql="Insert into Requests(Request_Text,Request_Sender_Id,Request_Time,Account_Id) values(?,?,?,?)";
         cnn=MyConnection.openConnection();
         stm=cnn.prepareStatement(sql);
         stm.setString(1, text);
         stm.setInt(2, toUser);
         stm.setString(3, sTime);
         stm.setInt(4, fromUserId);
         int status=stm.executeUpdate();
         if(status==1){
             return true;
         }

     } catch (Exception e) {
         System.out.println(e.getMessage());
     } finally{
         MyConnection.closeConnection(cnn, stm, null);
     }
     return false;
  }
  public static boolean insertImage(String fromUser,String imageTypeId,String imagePath){
       Connection cnn=null;
        PreparedStatement stm=null;
        int fromUserId=-1;
        int iTypeId=-1;

     try {
         iTypeId=Integer.parseInt(imageTypeId);
         fromUserId=selects.getAccountIdByAccountName(fromUser);
         String sql="Insert into Images(Account_Details_Id,Image_Type_Id,Image_Path) values(?,?,?)";
         cnn=MyConnection.openConnection();
         stm=cnn.prepareStatement(sql);
         stm.setString(1, fromUser);
         stm.setInt(2, iTypeId);
         stm.setString(3, imagePath);
         int status=stm.executeUpdate();
         if(status==1){
             return true;
         }

     } catch (Exception e) {
         System.out.println(e.getMessage());
     } finally{
         MyConnection.closeConnection(cnn, stm, null);
     }
     return false;
  }
  public static void main(String[] args){
      boolean s=Inserts.insertImage("7", "3", "2.jpeg");
  }
}
